<?php
/**
 * 商品列表
 * @author zhaofengjun
 */

namespace app\common\model;

use traits\model\SoftDelete;

class GoodsL extends Model
{
    use SoftDelete;
    protected $name = 'goods';
    protected $autoWriteTimestamp = true;


    /**
     * 获取商品下的所有订单信息
     */
    public function order()
    {
        return $this->hasMany('Orders','g_id','id');
    }

    /**
     * 获取当前分类的子分类
     */
    /*public function sub()
    {
        return $this->hasMany('GoodsL', 'goods_id')
            ->selfRelation();
    }*/


    protected function getStatusTextAttr($vaule, $data)
    {
        $text = [
            0 => '有货',
            1 => '无货'
        ];
        return $text[$data['status']];
    }

    protected function getLastLoginTimeAttr($value)
    {
        return $value>0?date('Y-m-d H:i:s',$value):'/';
    }


    protected function getRegTimeAttr($value)
    {
        return $value>0?date('Y-m-d H:i:s',$value):'/';
    }
}
